package commands;

import indexes.BattingIndex;
import indexes.PlayerIDIndex;
import indexes.PlayerNameIndex;

import java.io.IOException;
import java.util.List;

import util.BattingDatabaseFile;
import util.DatabaseFile;
import util.PlayerLogger;
/**
 * Provides a summary for each id within the given range.
 * @author xclite
 *
 */
public class ShowBattingSummaryRangeCommand extends Command
{

    /**
     * Typical constructor.
     * @param arguments
     */
    protected ShowBattingSummaryRangeCommand( List<String> arguments )
    {
        super( arguments );
    }

    @Override
    public boolean execute(
        PlayerIDIndex idIndex,
        PlayerNameIndex nameIndex,
        PlayerLogger logger,
        DatabaseFile database, BattingIndex battingIndex, BattingDatabaseFile battingDatabase ) throws IOException
    {
        logger.write(super.getDivider() + "\n");
        logger.write("Command: show__batting_summary_for " + getArguments().get(0) + " - " + getArguments().get(1) + "\n\n");
        List<Long> foundOffsets = battingIndex.getRange(getArguments().get(0), getArguments().get(1));
        
        for (Long offset: foundOffsets)
        {
            logger.write(battingDatabase.getBattingSummary(offset) + "\n");
        }
        return true;
    }

}
